package com.hundsun.cprs.yyt.web.action;

import com.hundsun.cprs.yyt.util.ExportExcelUtil;
import com.hundsun.cprs.yyt.util.SequenceUtils;
import com.hundsun.cprs.yyt.web.util.ExportExcelWrapper;
import com.hundsun.cprs.yyt.web.vo.excel.EntrustAuditExcelVo;
import com.hundsun.cprs.yyt.web.vo.excel.EntrustImportExcelVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author herong22384
 * @date 2019/8/15 17:02
 */
@Controller
@RequestMapping(("test/"))
public class TestAction extends BaseAction{

    @RequestMapping("entrust/import.htm")
    public void createExcel(HttpServletResponse response){
        List<EntrustImportExcelVo> datas = new ArrayList<>();
        String[] goodsCode = {"20190822002","20190822001","20190821001","20190819006","20190819005","20190819004","20190819003","20190819002","20190819001","20190813003"};
        String[] fundAccount = {"P000004000435","P000004000430","P000004000331","P000004000329","P000004000291","P000004000328","P000004000327","P000004000326","P000004000299","P000004000290"};
        Random r = new Random();
        for (int i = 1;i<= 80000;i++){
            int index = r.nextInt(10);
            EntrustImportExcelVo vo = new EntrustImportExcelVo();
            vo.setAmmount("5");
            vo.setBuyPrice(""+i);
            vo.setFundAccount(fundAccount[index]);
            vo.setGoodsCode(goodsCode[index]);
            vo.setOrderSn(SequenceUtils.generateSequence("50"));
            datas.add(vo);
        }

        String[] columnNames = { "订单编号","交易账号","商品编号","商品数量","成本价"};
        String fileName = "entrust_import";
        ExportExcelWrapper<EntrustImportExcelVo> util = new ExportExcelWrapper<EntrustImportExcelVo>();
        util.exportExcel(fileName, fileName, columnNames, datas, response, ExportExcelUtil.EXCEl_FILE_2007);

    }

    @RequestMapping("audit/import.htm")
    public void createAuditExcel(HttpServletResponse response){
        List<EntrustAuditExcelVo> datas = new ArrayList<>();
        String[] goodsCode = {"20190822002","20190822001","20190821001","20190819006","20190819005","20190819004","20190819003","20190819002","20190819001","20190813003"};
        String[] fundAccount = {"P000004000435","P000004000430","P000004000331","P000004000329","P000004000291","P000004000328","P000004000327","P000004000326","P000004000299","P000004000290"};
        Random r = new Random();
        for (int i = 0;i< 10;i++){
            //int index = r.nextInt(6);
            EntrustAuditExcelVo vo = new EntrustAuditExcelVo();
            vo.setFundAccount(fundAccount[i]);
            vo.setGoodsCode(goodsCode[i]);
            vo.setEntrustAmount(5L);
            vo.setAuditAmount(10L);
            datas.add(vo);
        }

        String[] columnNames = {"交易账号","商品编号","委托单商品数量","待审核单数"};
        String fileName = "audit_import";
        ExportExcelWrapper<EntrustAuditExcelVo> util = new ExportExcelWrapper<EntrustAuditExcelVo>();
        util.exportExcel(fileName, fileName, columnNames, datas, response, ExportExcelUtil.EXCEl_FILE_2007);

    }
}
